package Queue;

import java.util.Random;

public class ArrayCompareLoopAndLinkedList {

    public static void main(String[] args) {

        int opCount = 100000;
        Queue<Integer> arrayQueue = new ArrayQueue<Integer>();
        testQueue(arrayQueue,opCount);

        Queue<Integer> loopQueue = new LoopQueue<Integer>();
        testQueue(loopQueue,opCount);

        Queue<Integer> linkedListQueue = new LinkedListQueue<Integer>();
        testQueue(linkedListQueue,opCount);

    }

    private static void testQueue(Queue<Integer> queue,int opCount){
        long start = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            queue.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            queue.dequeue();
        }
        long end = System.nanoTime();
        System.out.println(queue.getClass()+"耗时:"+(end-start)/1000000000.0);
    }
}
